
    	var noteListGrid;
    	var index = 0;
    	var historyTree;
    	var myloader;
    	var sm = new Ext.grid.CheckboxSelectionModel();

	    Date.prototype.toString=function() {
			return this.format("Y-m-d");
		};
    	
        Ext.onReady(function(){
        	
        	// 构建历史数据列表
        	bulidNoteGrid();
			
			// 加载左侧时间树
			buildYearTree();

		   	var layout = new Ext.Viewport({   
	        	layout: 'border',   
	        	margins:'5 0 5 5',  
	       		renderTo :document.body,
	        	items: [
	        		{ 
	        			region: 'center',   
	                    // height:800,
	            		///title:'个人绩效档案',
	                    layout:'fit',
	                    items:[
			        			noteListGrid
						]  
	            	},{ region: 'west',   
	                   	width:120,
	            		split:true,
	            		collapsible:true,
						title:'时间选择',
				        containerScroll:true,
	                    items:[historyTree]  
	            	}]   
			});
			
			historyTree.root.expand();
			
		});
		
		// 构建grid
		var bulidNoteGrid = function() {
			
			var gridStore = new Ext.data.Store({
				proxy :new Ext.data.HttpProxy({
					url :'userJxda!getJxdaList.do'
				}),
				reader :new Ext.data.JsonReader({
					root :'result',
					totalProperty :'totalCount',
					//id : 'id',
					fields : ['id','rq', 'username', 'grjxdf', 'dadf', 'gzldf', 'gzzldf', 'zxkhdf', 'wzbts', 'pxdf', 'ksdf', 'xcbddf', 'cxcgdf','nr']
				}),
				autoLoad:false,
				remoteSort :false,
				params:{
					limit:pagelimit
				},
				listeners:{'beforeload' : function() {
					//storeGrid.baseParams['searchBean.con4'] = searchstate.value;
				}}
			});
			
		    var expander = new Ext.ux.grid.RowExpander({
		        tpl : new Ext.Template(
		            '<p><b>考核细则内容:</b> {nr}</p>'
		        )
		    });
			
			// 创建GridPanel
			noteListGrid = new Ext.grid.GridPanel({
				id:"noteList_grid",
				title:'个人绩效档案',
				store :gridStore,
				frame:true,
				//autoHeight:true,
				layout:'fit',
        		plugins: expander,
        		collapsible: true,
        		animCollapse: false,
				cm: new Ext.grid.ColumnModel({
            		defaults: {
                		sortable: true
            		},
            		columns: [
            			//new Ext.grid.RowNumberer(),
            			expander,
                		//sm,
    					{	id:'id',
							header :"序号",
							width :50,
							dataIndex :'id',
							sortable :true,
							hidden :true
						}, {
							header :"时间",
							width :50,
							dataIndex :'rq',
							sortable :false,
							align:'left'
						},{
							header :"姓名",
							width :50,
							dataIndex :'username',
							sortable :true,
							align:'center'
						}, {
							header :"个人绩效<br>得分",
							width:70,
							dataIndex :'grjxdf',
							sortable :true,
							align:'center'
						}, {
							header :"档案得分",
							dataIndex :'dadf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"工作量得分",
							dataIndex :'gzldf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"工作质量<br>得分",
							dataIndex :'gzzldf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"专项考核",
							dataIndex :'zxkhdf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"未值班天数",
							dataIndex :'wzbts',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"培训得分",
							dataIndex :'pxdf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"考试得分",
							dataIndex :'ksdf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"宣传报道<br>得分",
							dataIndex :'xcbddf',
							width:70,
							sortable :true,
							align:'center'
						}, {
							header :"创新成果<br>得分",
							dataIndex :'cxcgdf',
							width:70,
							sortable :true,
							align:'center'
						}]
				}),
				//sm:sm,
				loadMask : {msg :'载入中,请稍候...'},
				viewConfig:{forceFit:true},
				tbar :[

					{
						id :'noteList_delete',
						text :'删除',
						cls:'x-btn-text-icon',
        				icon:contextpath + '/images/delete.gif',
        				hidden:isAdmin,
        				handler:function() {
        					deleteNote();
        				}
					}
				],
				bbar :new Ext.PagingToolbar({
					//id:'gridLogBbar',
					pageSize :pagelimit,
					store :gridStore,
					displayInfo :true,
					displayMsg :'显示 {0} - {1} 共 {2} 条',
					emptyMsg :"没有数据显示！",
					beforePageText :"页码 ",
					afterPageText :"共 {0} 页",
					firstText :"首页",
					lastText :"末页",
					nextText :"下一页",
					prevText :"上一页",
					refreshText :"刷新"
				}),
				listeners:{'rowdblclick':function(row) {
					var r = noteListGrid.getSelectionModel().getSelected();
					//buildNoteUserGrid(r["id"], r.data["senddate"], r.data["note"], r.data["sendusername"]);
				}}
			});

		}
		
		// 构建左侧树
		var buildYearTree = function () {
			
			myloader = new Ext.tree.TreeLoader({
                	url : 'userJxda!getHistoryDate.do?flag='
            	}),

			/* 左侧历史数据的日期TREE */
       		historyTree = new Ext.tree.TreePanel({
                id:"historyTree",   
                root : new Ext.tree.AsyncTreeNode({   
            		id : "-1", 
            		draggable:false,
            		text : "绩效时间",
            		leaf:false,
            		icon:contextpath + '/images/time.gif'
				}),   
				loader:myloader,
                //rootVisible:false,
		        useArrows:true,
		        autoScroll:true,
		        animate:true,
		        border:false,
		        listeners:{"click":function(node){ 
//					if (node.isLeaf() != undefined && node.isLeaf()){
//	          			 
//	                } else {
//	                	if (!node.isExpanded()) {
//	                		node.expand();		
//	                	} else {
//	                		node.collapse();
//	                	}              
//	                }
//	                // 月时加载数据
//	                if (node.text.length == 2 && node.text != "") {
//	                	
	                	Ext.getCmp("noteList_grid").store.baseParams['searchBean.con10'] = node.id;
	                	Ext.getCmp("noteList_grid").store.reload();
	                	
//						Ext.getCmp("noteTabBase").items.each(function(item){
//	                         if(item.closable)
//	                         {
//	                            Ext.getCmp("noteTabBase").remove(item);
//	                         }
//						});
//	                }
            	}}	
            });

        	myloader.on("beforeload", function(loader, node) { 
        		// 根节点 只查询 年
				if( node.id == "-1") {
					loader.url ='userJxda!getHistoryDate.do?flag=-1';
					return;
				} else {
					loader.url ='userJxda!getHistoryDate.do?flag=' + node.text;
				}
    		});

        	myloader.on("load", function(loader, node) { 
       
    			if (node.childNodes.length > 0) {

    				for(var i =0;i<node.childNodes.length;i++) {
						
    					// 如果是当前年 接着打开当前月
						if(node.childNodes[i].text == today.split("-")[0]) {
							node.childNodes[i].expand();
						} else {
							// 如果是当前月 接着查询
							if(node.childNodes[i].id == today.split("-")[0] + "-" + today.split("-")[1]) {
								node.childNodes[i].select();
								Ext.getCmp("noteList_grid").store.baseParams['searchBean.con10'] = node.childNodes[i].id;
								Ext.getCmp("noteList_grid").store.reload();
								
//								Ext.getCmp("noteTabBase").items.each(function(item){
//			                         if(item.closable)
//			                         {
//			                            Ext.getCmp("noteTabBase").remove(item);
//			                         }
//								});
							}
						}
					}
    			}

            });

		}
		
		// 删除
		function deleteNote() {
		
			if (!Ext.getCmp("noteList_grid").getSelectionModel().hasSelection()) {
				Ext.MessageBox.alret("提示","请先选择要删除的记录");
				return;
			}
				
			Ext.MessageBox.confirm("提示","确定要删除选中记录吗？",function (btn) {
				
				if (btn == 'yes') {

					var ids = '';
					var records = Ext.getCmp("noteList_grid").getSelectionModel().getSelections();
					for ( var i = 0; i < records.length; i++) {
						if (i == 0) {
							ids = records[0].data["id"];
						} else {
								ids += ',' + records[i].data["id"];
						}
					}

					Ext.Ajax.request({
						method :'POST',
						url :'userJxda!delete.do',
						params : {
							id :ids
						},
						success : function(response) {
							Ext.MessageBox.alert('提示', Ext.decode(response.responseText).msg);
							Ext.getCmp("noteList_grid").store.reload();
							historyTree.root.reload();
							historyTree.root.expand();
						},
						failure : function() {
								Ext.MessageBox.alert('提示', '删除失败！');
						}
					});
				}
			});
		
		}
